package com.dailyblue.project.smbms.alibaba.order.listener;

import com.alibaba.fastjson.JSONArray;
import com.dailyblue.project.smbms.alibaba.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Map;

@Slf4j
@Component
@RocketMQMessageListener(topic = "Alipay", selectorExpression = "tag", consumerGroup = "alipay_group_consumer", messageModel = MessageModel.BROADCASTING)
public class OrderListener implements RocketMQListener<String> {
    @Resource
    private OrderService service;

    @Override
    public void onMessage(String s) {
        log.info("消费的字符串:{}", s);
        Map<String, String> map = JSONArray.parseObject(s, Map.class);
        log.info("转换之后的集合是:{}", map);
        String orderId = map.get("orderId");
        String aid = map.get("aid");
        String order = map.get("order");
        log.info("orderId:{},aid:{},order:{}", orderId, aid, order);
        service.saveOrder(orderId, aid, order);
    }
}
